package com.example.smartcommunity;

import android.annotation.SuppressLint;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;


public class PersonimageActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView back2, changetx;

    private String[] items = {"拍一张", "从相册选取"};

    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personimage);

        changetx = findViewById(R.id.changetx);
        initListener();

        ImageView back2 = findViewById(R.id.back2);
        back2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initListener() {
        changetx.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.changetx:

                showDialog();

                break;
        }
    }

    private void showDialog() {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        final AlertDialog mDialog = builder.create();

        View view = View.inflate(getApplicationContext(), R.layout.activity_person_dialog, null);

        Button btn = view.findViewById(R.id.cancel);
        TextView tv_phone = view.findViewById(R.id.tv_phone);
        TextView tv2 = view.findViewById(R.id.tv2);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialog.dismiss();
            }
        });
        tv_phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE_SECURE);
                startActivityForResult(intent ,222);
                mDialog.dismiss();
            }
        });
        tv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent();
                intent1.setAction(Intent.ACTION_GET_CONTENT);
                intent1.addCategory(Intent.CATEGORY_OPENABLE);
                intent1.setType("image/*");
                startActivityForResult(intent1,111);
                mDialog.dismiss();
            }
        });

        mDialog.setView(view);

        Window window = mDialog.getWindow();

        window.setGravity(Gravity.BOTTOM);

        window.setWindowAnimations(R.style.popupAnimation);

        mDialog.setCanceledOnTouchOutside(true);

        mDialog.setCancelable(false);

        mDialog.show();

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode){

            case 111:
                break;

        }
    }
}
